package com.zego.wawaji.ui.bean.pay;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONObject;

/**
 * 支付单商品
 * Created by Su on 2017/12/1.
 */
public class Pay extends BaseData implements Parcelable {
    private int id;
    private int wwCoinCz;    // 用户充值的娃娃币数量
    private int wwCoinZs;    // 赠送收获的娃娃币
    private double price;       // 商品价格
    private String remark;   // 商品描述信息
    private int status;
    private int sortId;      // 排序id

    private int isNew;       // 是否是新手礼包  == 1 是
    private int enableBuy;   // 是否可以购买  == 1 可以购买

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);

        this.setId(jsonObject.optInt("Id"));
        this.setWwCoinCz(jsonObject.optInt("WwCoinCz"));
        this.setWwCoinZs(jsonObject.optInt("WwCoinZs"));
        this.setPrice(jsonObject.optDouble("Amount"));
        this.setRemark(jsonObject.optString("Remark"));
        this.setStatus(jsonObject.optInt("Status"));
        this.setSortId(jsonObject.optInt("SortId"));

        this.isNew = jsonObject.optInt("IsNew");
        this.enableBuy = jsonObject.optInt("EnableBuy");
    }

    /**
     * 是否是新用户礼包
     *
     * @return true 是
     */
    public boolean isNew() {
        return isNew == 1;
    }

    /**
     * 是否可以购买
     *
     * @return true 可以购买
     */
    public boolean enableBuy() {
        return enableBuy == 1;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getWwCoinCz() {
        return wwCoinCz;
    }

    public void setWwCoinCz(int wwCoinCz) {
        this.wwCoinCz = wwCoinCz;
    }

    public int getWwCoinZs() {
        return wwCoinZs;
    }

    public void setWwCoinZs(int wwCoinZs) {
        this.wwCoinZs = wwCoinZs;
    }

    public int getIntPrice() {
        return (int) price;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getSortId() {
        return sortId;
    }

    public void setSortId(int sortId) {
        this.sortId = sortId;
    }

    public Pay() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeInt(this.wwCoinCz);
        dest.writeInt(this.wwCoinZs);
        dest.writeDouble(this.price);
        dest.writeString(this.remark);
        dest.writeInt(this.status);
        dest.writeInt(this.sortId);
        dest.writeInt(this.isNew);
        dest.writeInt(this.enableBuy);
    }

    protected Pay(Parcel in) {
        this.id = in.readInt();
        this.wwCoinCz = in.readInt();
        this.wwCoinZs = in.readInt();
        this.price = in.readDouble();
        this.remark = in.readString();
        this.status = in.readInt();
        this.sortId = in.readInt();
        this.isNew = in.readInt();
        this.enableBuy = in.readInt();
    }

    public static final Creator<Pay> CREATOR = new Creator<Pay>() {
        @Override
        public Pay createFromParcel(Parcel source) {
            return new Pay(source);
        }

        @Override
        public Pay[] newArray(int size) {
            return new Pay[size];
        }
    };
}
